<?php
/**
 * Nadëb (Makú-Nadëb)
 * 
 * @author     Mateus Martins <mateusweb@gmail.com>
 * @copyright  Copyright 2010 mateusweb.com.br
 * @license    http://www.gnu.org/licenses/gpl.html | GPL
 * @package    Nadeb
 * @version    1.0.0
 */


/**
 * Class Nadeb_Report_ShowData_Imagecrop
 * Monta uma tag de imagem
 * 
 * @category   Nadeb
 * @package    Nadeb_Report_ShowData_Imagecrop
 * @copyright  Copyright 2010 mateusweb.com.br
 * @license    http://www.gnu.org/licenses/gpl.html | GPL
 */
class Nadeb_Report_ShowData_Imagecrop extends Nadeb_Report_ShowData_Variables
{
	/**
	 * @var object
	 */
	protected static $_instance = null;
	
	/**
	 * @var array
	 */
	public $JSInstances;
	
	/**
	 * Metodo Construtor
	 * 
	 * @return void
	 */
	private function __construct()
	{
		$js             = Nadeb_JScontroller::get_instance();
		$js->JSInstance = "admin_lightbox";
	}
	
    /**
     * Retorna a instancia de Nadeb_Report_ShowData_Imagecrop
     * Implementação do Singleton pattern 
     *
     * @return Nadeb_JScontroller
     */
    public static function get_instance()
    {
        if (null === self::$_instance)
        {
            self::$_instance = new self();
        }

        return self::$_instance;
    }
	
    public function get_xhtml()
    {
    	$ar_param = explode(",",$this->params);
    	$patch    = $ar_param[0];
    	$file     = $this->string;
    	$width    = $ar_param[1];
    	$height   = $ar_param[2];

		@mkdir($_SERVER["DOCUMENT_ROOT"] . $patch . '/temp/', 0777,true);
		@chmod($_SERVER["DOCUMENT_ROOT"] . $patch . '/temp/', 0777,true);
    	
		if( !is_file( $_SERVER["DOCUMENT_ROOT"] . $patch . "temp/nadeb-temp-{$file}" ) )
		{
	    	$image = new Nadeb_CropImages();
	    	$image->set_patch( $patch )
	    	      ->set_file( $file )
	    	      ->set_newName(  "temp/nadeb-temp-{$file}" )
	    	      ->set_newSize($width,$height)
	    	      ->create()
	    	      ->auto_crop()
	    	      ->make_file();
		}
    	
		$xhtml = "<a href=\"/public/uploads/{$this->string}\" class=\"lightbox\"><img src='/public/uploads/temp/nadeb-temp-{$this->string}' width='{$ar_param[1]}' height='{$ar_param[2]}' alt='-' /></a>";
					
    	return $xhtml;
    }
    
	
}
